import sys
import traceback
import pygame

from game.system.go.core.GoEvent import GoEvent
from game.system.go.core.GoRuleManager import GoRuleManager



def main():
    # pygame初始化
    pygame.init()
    # 窗口长宽
    size = width, height = 850, 850
    screen = pygame.display.set_mode(size, 0, 32)
    pygame.display.set_caption('莫莫绵围棋')
    # 设置字体
    font = pygame.font.Font('./font/simhei.ttf', 48)
    clock = pygame.time.Clock()  # 设置时钟
    gameOver = False
    goRule = GoRuleManager()  # Renju是核心类，实现落子及输赢判断等
    goEvent = GoEvent(goRule)
    goRule.init()  # 初始化
    runGame = True
    while runGame:
        clock.tick(20)  # 设置帧率
        for event in pygame.event.get():
            # 事件处理
            if event.type == pygame.QUIT:
                runGame = False
            if event.type == pygame.MOUSEBUTTONDOWN and (not gameOver):
                gameOver = goEvent.mouseButtonOnDownEvent(event, font, gameOver, height, width)

        screen.blit(goRule.getChessboard(), (0, 0))
        pygame.display.update()

    pygame.quit()
    sys.exit()







if __name__ == "__main__":
    try:
        main()
    except SystemExit:
        pass
    except Exception as e :
        traceback.print_exc()
        print(str(e))
        #退出
        pygame.quit()
    input()